package logic

import (
	"context"
	"exam/docker/mysql"

	"exam/exzmrpc/exzmrpc"
	"exam/exzmrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LimitLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLimitLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LimitLogic {
	return &LimitLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LimitLogic) Limit(in *exzmrpc.LimitRequest) (*exzmrpc.LimitResponse, error) {
	// todo: add your logic here and delete this line
	var user []mysql.User

	mysql.DB.Debug().Where("Id = ?", in.UserId).Find(&user)
	var deme []*exzmrpc.Limit

	for _, i2 := range user {
		list := exzmrpc.Limit{
			UserId: int64(i2.ID),
			Title:  i2.Title,
			Number: int64(i2.Number),
			Types:  int64(i2.Types),
		}
		deme = append(deme, &list)
	}

	return &exzmrpc.LimitResponse{
		List: deme,
	}, nil
}
